package com.tangyuan.user.service.impl;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.pagehelper.PageInfo;
import com.tangyuan.common.result.Result;
import com.tangyuan.common.util.CommStatus;
import com.tangyuan.feignapis.headlines.IHeadlinesFeignClient;
import com.tangyuan.model.*;
import com.tangyuan.user.mapper.UserSearchMapper;
import com.tangyuan.user.service.UserSearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class UserArticleSearchImpl implements UserSearchService {

    @Autowired
    UserSearchMapper userSearchMapper;

    @Autowired
    private IHeadlinesFeignClient headlinesFeignClient;


    @Override
    public Result userSearch(Integer pageNum, Integer pageSize,String  name,String token) {
        User user = CommStatus.getUser(token);
        Page<Headlines> page = headlinesFeignClient.searchArticle(user.getId(),name, pageNum, pageSize);
        PageInfo<Headlines> pageInfo = new PageInfo<>(page.getRecords());
        pageInfo.setPageNum(pageNum);
        pageInfo.setPageSize(pageSize);
        pageInfo.setTotal(page.getCurrent());
        return Result.ok(pageInfo);
    }
}

